package com.lineage.data.item_etcitem.html;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.Random;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Wenyangcishu extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(Wenyangcishu.class);
  
  Random _random = new Random();
  
  private int _type;
  
  private int _reduceCount;
  
  public static ItemExecutor get() {
    return new Wenyangcishu();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    try {
      if (pc == null)
        return; 
      if (pc.isDead())
        return; 
      if (pc.isPrivateShop())
        return; 
      switch (this._type) {
        case 1:
          pc.setyiwacishu(pc.getyiwacishu() - this._reduceCount);
          if (pc.getyiwacishu() <= 0)
            pc.setyiwacishu(0); 
          break;
        case 2:
          pc.setshahacishu(pc.getshahacishu() - this._reduceCount);
          if (pc.getshahacishu() <= 0)
            pc.setshahacishu(0); 
          break;
        case 3:
          pc.setmapulecishu(pc.getmapulecishu() - this._reduceCount);
          if (pc.getmapulecishu() <= 0)
            pc.setmapulecishu(0); 
          break;
        case 4:
          pc.setpageliaocishu(pc.getpageliaocishu() - this._reduceCount);
          if (pc.getpageliaocishu() <= 0)
            pc.setpageliaocishu(0); 
          break;
        case 5:
          pc.setyinhaisacishu(pc.getyinhaisacishu() - this._reduceCount);
          if (pc.getyinhaisacishu() <= 0)
            pc.setyinhaisacishu(0); 
          break;
        case 6:
            pc.setgelankencishu(pc.getgelankencishu() - this._reduceCount);
            if (pc.getgelankencishu() <= 0)
              pc.setgelankencishu(0); 
            break;
      } 
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("获得[" + this._reduceCount + "]次强化机会"));
      pc.getInventory().removeItem(item, 1L);
      pc.save();
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._type = Integer.parseInt(set[1]);
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
    try {
      this._reduceCount = Integer.parseInt(set[2]);
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
